import { javascriptGenerator } from 'blockly/javascript';
import { syncLogGenerators } from './sync-log-generators';
import { asyncLogGenerators } from './async-log-generators';
import { asyncFunctionGenerators } from './async-function-generators';
import { registerVariableGenerators } from './javascript-variable-generator';
import { systemFunctionGenerators } from './system-function-generators';

// 全局跟踪注册状态
let generatorsRegistered = false;

// 注册所有代码生成器
export function registerGenerators() {
  // 如果已经注册过，直接返回
  if (generatorsRegistered) {
    return;
  }
  try {
    // 注册同步日志生成器
    Object.assign(javascriptGenerator.forBlock, syncLogGenerators);
    
    // 注册异步日志生成器
    Object.assign(javascriptGenerator.forBlock, asyncLogGenerators);
    
    // 注册异步函数生成器
    Object.assign(javascriptGenerator.forBlock, asyncFunctionGenerators);
    
    // 注册系统函数生成器
    Object.assign(javascriptGenerator.forBlock, systemFunctionGenerators);
    
    // 注册变量生成器
    registerVariableGenerators();

   // 检查生成器注册情况
    console.log('Total generator keys:', Object.keys(javascriptGenerator.forBlock).length);
    // 标记为已注册
    generatorsRegistered = true;
  } catch (error) {
    console.error('Error registering generators:', error);
  }
}
